<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author Cheng
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'management:inFireNotification:edit'">
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ tid: record.tid })">
          {{ record.mainId }}
        </a>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup name="ViewsManagementInFireNotificationList">
  import { unref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { inFireNotificationDelete, inFireNotificationListData } from '/@/api/management/FireNotice';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import { useRoute } from 'vue-router';

  const { t } = useI18n('management.inFireNotification');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);
  const route=useRoute();
  console.log('route.query',route.query)

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('火情通知表'),
  };

  const searchForm: FormProps = {
    baseColProps: { md: 8, lg: 6 },
    labelWidth: 90,
    schemas: [
      {
        label: t(''),
        field: 'unitName',
        component: 'Input',
        componentProps:{
          placeholder: t('请输入通知的单位'),
        }
      },
      {
        label: t(''),
        field: 'notifierName',
        component: 'Input',
        componentProps:{
          placeholder:t('通知人姓名')
        }
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('通知的单位名称'),
      dataIndex: 'unitName',
      key: 'a.unit_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('火情联动级别'),
      dataIndex: 'linkageLevel',
      key: 'a.linkage_level',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('通知人姓名'),
      dataIndex: 'notifierName',
      key: 'a.notifier_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('通知是否已被确认'),
      dataIndex: 'confirmed',
      key: 'a.confirmed',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('通知确认的时间'),
      dataIndex: 'confirmTime',
      key: 'a.confirm_time',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('通知人联系方式'),
      dataIndex: 'notifierPhone',
      key: 'a.notifier_phone',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('通知内容'),
      dataIndex: 'notifierContent',
      key: 'a.notifier_content',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];


  const [registerTable, { reload }] = useTable({
    api: inFireNotificationListData,
    beforeFetch: (params) => {
      if(route.query){
        params.moduleName=route.query.moduleName;
      }
      return params;
    },
    columns: tableColumns,
    // actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  const [registerDrawer, { openDrawer }] = useDrawer();

  // function handleForm(record: Recordable) {
  //   openDrawer(true, record);
  // }

  // async function handleDelete(record: Recordable) {
  //   const params = { tid: record.tid };
  //   const res = await inFireNotificationDelete(params);
  //   showMessage(res.message);
  //   handleSuccess(record);
  // }

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
